﻿using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Button button = new Button();
            button.Text = "Click me";
            button.Click += LogPlainEvent;      // 使用方法组转换
            button.KeyPress += LogKeyEvent;         // 使用转换和逆变性
            button.MouseClick += LogMouseEvent;     // 使用转换和逆变性
            this.Controls.Add(button);
        }

        static void LogPlainEvent(object sender, EventArgs e)   //处理所有事件
        {
            Console.WriteLine("An Event occurred");
        }
        static void LogKeyEvent(object sender, KeyPressEventArgs e)
        {
            Console.WriteLine("LogKey");
        }
        static void LogMouseEvent(object sender, MouseEventArgs e)
        {
            Console.WriteLine("LogMouse");
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        void EventHandler(object sender, EventArgs e) { }
        void KeyPressEventHandler(object sender, KeyPressEventArgs e) { }
        void MouseEventHandler(object sender, MouseEventArgs e) { }
    }
}
